package com.yanqu.road.server.cmd.activity.flowerstudy.fromcross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FlowerStudyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.flowerstudy.FlowerStudyModule;
import com.yanqu.road.server.manger.activity.flowerstudy.FlowerStudyMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_FLOWER_STUDY_EXAM_EVENT_SYNC_RESULT_FROM_CROSS, desc = "花城书房考试结算事件同步")
public class FlowerStudyExamEventSyncCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        FlowerStudyProto.syncExamResultToGameServer toGameServer = FlowerStudyProto.syncExamResultToGameServer.parseFrom(packet.getBytes());
        GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(toGameServer.getUserId());
        if (onlinePlayer != null) {
            onlinePlayer.getModule(FlowerStudyModule.class).dealExamEventSync(toGameServer.getRoomData());
        }else {
            log.error("玩家不在线，特殊处理花城书房，userId:{}",toGameServer.getUserId());
            FlowerStudyMgr.dealOfflineExamEventSync(toGameServer.getUserId(), toGameServer.getRoomData());
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
